/**
 * 
 */
package com.precisosoft.mathematize.server;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.allen_sauer.gwt.log.client.Log;
import com.precisosoft.mathematize.server.dao.UserDao;
import com.precisosoft.mathematize.server.domain.User;
import com.precisosoft.mathematize.server.util.Security;

/**
 * @author jewettdx
 *
 */
public class AccountTestCase {
	 private long startTimeMillis;

	  @Before
	  public void setUp() {

	    // The log4j configuration file must be in the Project's root directory
	    DOMConfigurator.configure("log4j.xml");

	    // When developing applications with Hibernate, you should almost always work
	    // with debug enabled for the category org.hibernate.SQL, or, alternatively,
	    // the property hibernate.show_sql enabled.
	    Logger.getLogger("org.hibernate.SQL").setLevel(Level.DEBUG);
	    // Logger.getLogger("org.hibernate").setLevel(Level.WARN);
	    // Logger.getLogger("org.hibernate.cache").setLevel(Level.WARN);

	    startTimeMillis = System.currentTimeMillis();
	  }

	  @After
	  public void tearDown() {
	    long endTimeMillis = System.currentTimeMillis();
	    float durationSeconds = (endTimeMillis - startTimeMillis) / 1000F;
	    Log.debug("Duration: " + durationSeconds + " seconds");
	  }

	  @Test
	  public void testAccountDao() {
	    try {
	      Log.debug("testAccountDao()");

	      // for (int i = 1; i <= 256; i++ ) {
	      //   createAccount(i);
	      // }

	      createUsers();

	    }
	    catch (Exception e) {
	      Log.error("e: " + e);
	      e.printStackTrace();
	    }
	  }

	  public void createUsers() {

	    User user1 = new User();
	    user1.setLogin("Administrator");

	    String salt = Security.randomCharString();
	    Log.debug("salt: " + salt);

	    String password = "N0M0r3$ecrets";
	    String hash = Security.sha256(salt + password);
	    user1.setSalt(salt);
	    user1.setPassword(hash);

	    UserDao userDao = new UserDao();
	    userDao.createUser(user1);
	  }


}
